home *** CD-ROM | disk | FTP | other *** search
- *-----------------------------------------------------------------------
- *-- Program...: NAVIGATE.PRG
- *-- Programmer: Ken Mayer (CIS: 71333,1030)
- *-- Date......: 09/01/1993
- *-- Notes.....: These are interesting functions designed to help out in
- *-- navigation ... see the file: README.TXT for details on
- *-- the use of this library file.
- *-- NOTE -- a few functions have been added into this
- *-- library that are duplicated elsewhere (other library
- *-- files). This is due to a limitation with dBASE IV,
- *-- 1.5's handling of libraries.
- *-- These functions are (and are from):
- *-- STRIP2VAL() from STRINGS.PRG
- *-- STRIPVAL()
- *-- STRPBRK()
- *-- HAV() from TRIG.PRG
- *-- AHAV()
- *-- CSCH()
- *-- SINH()
- *-----------------------------------------------------------------------
-
- FUNCTION Correct
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Correction of direction - adjusts direction given, in
- *-- degrees, by second number of degrees. Use to convert
- *-- a compass direction to magnetic using deviation as the
- *-- second argument, or magnetic to true using variation
- *-- as the second argument. Returns a direction in
- *-- degrees.
- *--
- *-- A westerly second argument may be given either as a
- *-- negative number or as a character value containing
- *-- "W". If second argument is character-type but
- *-- contains a negative value, effect of presence or
- *-- absence of "W" is reversed. That is, "-20 W" is
- *-- treated like "20 E" or the number 20.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Correct(<nDirection>,<xCorrection>)
- *-- Example.....: ?Correct(50,"-10 E")
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nDirection = Heading
- *-- xCorrection = amount to 'correct' by, may be numeric
- *-- or character, see above under 'Notes'.
- *-----------------------------------------------------------------------
-
- parameters nDirection, xCorrection
- private nCval
- if type( "xCorrection" ) = "C"
- m->nCVal = val( m->xCorrection )
- if "W" $ upper( m->xCorrection )
- m->nCVal = - m->nCVal
- endif
- else
- m->nCVal = m->xCorrection
- endif
-
- RETURN mod( 360 + m->nDirection + m->nCVal, 360 )
- *-- EoF: Correct()
-
- FUNCTION UnCorrect
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Uncorrection of direction - adjusts direction given,
- *-- in degrees, by second number of degrees. The inverse
- *-- of correct(), see above. Use to convert a true
- *-- direction to magnetic using variation as the second
- *-- argument, or magnetic to compass using deviation as
- *-- the second argument.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: UnCorrect(<nDirection>,<xUnCorr>)
- *-- Example.....: ?UnCorrect(50,"-10 E")
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nDirection = Heading
- *-- xUnCorr = amount to 'uncorrect' by, may be numeric
- *-- or character, see above under 'Notes'.
- *-----------------------------------------------------------------------
-
- parameters nDirection, xUncorr
- private m->nCVal
- if type( "xUncorr" ) = "C"
- m->nCVal = val( m->xUncorr )
- if "W" $ upper( m->xUncorr )
- m->nCVal = - m->nCVal
- endif
- else
- m->nCVal = m->xUncorr
- endif
-
- RETURN mod( 360 + m->nDirection - m->nCVal, 360 )
- *-- EoF: UnCorrect()
-
- FUNCTION XAngle
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Angle in degrees ( <= 90 ) at which two vectors in
- *-- degrees intersect.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: XAngle(<nVector1>,<nVector2>)
- *-- Example.....: ?UnCorrect(20,240)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nVector1 = First angle
- *-- nVector2 = Second angle
- *-----------------------------------------------------------------------
-
- parameters nVector1, nVector2
- private nResult
- m->nResult = abs( m->nVector1 - m->nVector2)
- do case
- case m->nResult > 270
- m->nResult = 360 - m->nResult
- case m->nResult > 180
- m->nResult = m->nResult - 180
- case m->nResult > 90
- m->nResult = 180 - m->nResult
- endcase
-
- RETURN m->nResult
- *-- EoF: XAngle()
-
- FUNCTION LeftWind
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Whether effect of second vector on first is from the
- *-- left or the right. Returns .T. if from the left, else
- *-- .F. Expects vectors in degrees.
- *--
- *-- For convenience in aviation calculations, the second
- *-- argument is expected as the direction FROM which
- *-- the wind or current is coming, not the direction TO
- *-- which it is going. If the contrary sense
- *-- is more convenient, change the "=" sign in the
- *-- function to "#".
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: LeftWind(<nCourse>,<nWindFrom>)
- *-- Example.....: ?LeftWind(20,240)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nCourse = Direction of heading ...
- *-- nWindFrom = Direction wind or current is coming from
- *-----------------------------------------------------------------------
-
- parameters nCourse, nWindfrom
-
- RETURN ( m->nCourse > m->nWindfrom ) = ( abs( m->nCourse - ;
- m->nWindfrom ) < 180 )
- *-- EoF: LeftWind()
-
- FUNCTION TailWind
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Whether effect of second vector on first is additive
- *-- or subtractive ( from behind or from ahead ).
- *--
- *-- For convenience in aviation calculations, the second
- *-- argument is expected as the direction FROM which
- *-- the wind or current is coming, not the direction TO
- *-- which is going. If the contrary sense
- *-- is more convenient, change the "<" sign in the
- *-- function to ">".
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: TailWind(<nCourse>,<nWindFrom>)
- *-- Example.....: ?TailWind(20,240)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nCourse = Direction of heading ...
- *-- nWindFrom = Direction wind or current is coming from
- *-----------------------------------------------------------------------
-
- parameters nCourse, nWindfrom
-
- RETURN ( abs( abs( m->nCourse - m->nWindfrom ) - 180 ) < 90 )
- *-- EoF: TailWind()
-
- FUNCTION Heading
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Heading required to make good a course.
- *-- If using this for boating and the direction of set is
- *-- more convenient than the direction from which
- *-- it is coming, apply mod( 180 + direction, 360 )
- *-- to the fourth argument before calling.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: XANGLE() Function in NAVIGATE.PRG
- *-- LEFTWIND() Function in NAVIGATE.PRG
- *-- Called by...: Any
- *-- Usage.......: Heading(<nCourse>,<nAirSpeed>,<nWindFrom>,<nForce>)
- *-- Example.....: ?Heading(20,5,240,2)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nCourse = Direction of heading ...
- *-- nAirSpeed = What it says
- *-- nWindFrom = Direction wind or current is coming from
- *-- nForce = Windforce
- *-----------------------------------------------------------------------
-
- parameters nCourse, nAirspeed, nWindfrom, nForce
- private nCrabAngle
- m->nCrabAngle = rtod( asin( m->nForce * ;
- sin( dtor( xangle( m->nCourse, m->nWindFrom))) ;
- / m->nAirSpeed ) )
- m->nCrabAngle = iif( leftwind( m->nCourse, m->nWindFrom ),;
- -m->nCrabAngle, m->nCrabAngle )
- m->nCrabAngle = mod( 360 + m->nCourse + m->nCrabAngle, 360 )
-
- RETURN iif( abs( m->nCrabAngle ) < 360, m->nCrabAngle, -1 )
- *-- EoF: Heading()
-
- FUNCTION Course
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Course made good given heading, speed and wind
- *-- direction and force.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: XANGLE() Function in NAVIGATE.PRG
- *-- LEFTWIND() Function in NAVIGATE.PRG
- *-- TAILWIND() Function in NAVIGATE.PRG
- *-- Called by...: Any
- *-- Usage.......: Course(<nHeading>,<nAirSpeed>,<nWindFrom>,<nForce>)
- *-- Example.....: ?Course(20,5,240,2)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nHeading = Direction of heading ...
- *-- nAirSpeed = What it says
- *-- nWindFrom = Direction wind or current is coming from
- *-- nForce = Windforce
- *-----------------------------------------------------------------------
-
- parameters nHeading, nAirspeed, nWindfrom, nForce
- private nTemp, nCrabAngle
- m->nTemp = dtor( xangle( m->nHeading, m->nWindFrom ) )
- m->nCrabAngle = m->nAirSpeed - m->nForce * cos( m->nTemp ) ;
- * iif( tailwind( m->nHeading, m->nWindFrom ), -1, 1 )
- if m->nCrabAngle < 0
- m->nCrabAngle = 0
- else
- m->nCrabAngle = abs( rtod( atan( m->nForce * sin( m->nTemp );
- / m->nCrabAngle ) ) )
- m->nCrabAngle = iif( leftwind( m->nHeading,m->nWindFrom ),;
- m->nCrabAngle, -m->nCrabAngle)
- endif
-
- RETURN mod( 360 + m->nHeading + m->nCrabAngle, 360 )
- *-- EoF: Course()
-
- FUNCTION GndSpeed
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Speed over the ground given heading, speed
- *-- and wind direction and force.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: XANGLE() Function in NAVIGATE.PRG
- *-- TAILWIND() Function in NAVIGATE.PRG
- *-- Called by...: Any
- *-- Usage.......: GndSpeed(<nHeading>,<nAirSpeed>,<nWindFrom>,<nForce>)
- *-- Example.....: ?GndSpeed(20,5,240,2)
- *-- Returns.....: Numeric (direction in degrees)
- *-- Parameters..: nHeading = Direction of heading ...
- *-- nAirSpeed = What it says
- *-- nWindFrom = Direction wind or current is coming from
- *-- nForce = Windforce
- *-----------------------------------------------------------------------
-
- parameters nHeading, nAirspeed, nWindfrom, nForce
- private nTemp
- m->nTemp = cos( dtor( xangle( m->nHeading, m->nWindFrom ) ) ) ;
- * iif( tailwind( m->nHeading, m->nWindFrom ), -1, 1 )
- m->nTemp = m->nAirSpeed * m->nAirSpeed + m->nForce * m->nForce ;
- - 2 * m->nAirSpeed * m->nForce * m->nTemp
-
- RETURN iif(m->nTemp<=0,m->nAirSpeed+m->nForce*iif(tailwind(m->nHeading,;
- m->nWindFrom ),1,-1),sqrt(m->nTemp))
- *-- EoF: GndSpeed()
-
- FUNCTION Deg2Num
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Degrees to number: String in the form " 40d50'30.2 N"
- *-- is converted to a number of degrees. If followed by
- *-- E or S, sign will be reversed.
- *--
- *-- It doesn't matter what characters are used to separate
- *-- the degrees, minutes and seconds, but any of the
- *-- characters N, E, W and S or their lowercase
- *-- equivalents following the last digit will be
- *-- understood as specifying a compass direction.
- *--
- *-- If the degrees or minutes are 0, they must never-
- *-- theless be included in the argument. Seconds may
- *-- be omitted if 0, as may the minutes if 0 and seconds
- *-- are omitted.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1993 -- Original Release
- *-- Calls.......: STRIP2VAL() Function in STRINGS.PRG
- *-- STRIPVAL() Function in STRINGS.PRG
- *-- STRPBRK() Function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: Deg2Num(<cDms>)
- *-- Example.....: ?Deg2Num("40d50'30.2 N")
- *-- Returns.....: Numeric (degrees)
- *-- Parameters..: cDms = Degrees Minutes Seconds
- *-----------------------------------------------------------------------
-
- parameters cDms
- private nResult, cStrleft
- if type( "cDms" ) $ "NF"
- RETURN m->cDms
- endif
- m->cStrLeft = strip2val( m->cDms )
- m->nResult = val( m->cStrLeft )
- if "" # strip2val( stripval( m->cStrLeft ) )
- m->cStrLeft = strip2val( stripval( m->cStrLeft ) )
- m->nResult = m->nResult + val( m->cStrLeft ) / 60
- if "" # strip2val( stripval( m->cStrLeft ) )
- m->cStrLeft = strip2val( stripval( m->cStrLeft ) )
- m->nResult = m->nResult + val( m->cStrLeft ) / 3600
- endif
- endif
- m->cStrLeft = upper( ltrim( stripval( m->cStrLeft ) ) )
- if strpbrk("NW", m->cStrLeft ) > 0 .or. strpbrk( "ES",m->cStrLeft )=0
- RETURN m->nResult
- else
- RETURN -m->nResult
- endif
-
- *-- EoF: Deg2Num()
-
- FUNCTION BearsDist
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Distance to an object at the time of the second
- *-- bearing, given two bearings and the distance run
- *-- between them. Value returned will be in same
- *-- units as third argument; first two are in degrees.
- *-- Returns -1 if already past the object.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: BearsDist(<nBear1>,<nBear2>,<nRun>)
- *-- Example.....: ?BearsDist(200,150,5)
- *-- Returns.....: Numeric (degrees)
- *-- Parameters..: nBear1 = Bearing of First object
- *-- nBear2 = Bearing of Second object
- *-- nRun = Distance (or time) run between bearings
- *-----------------------------------------------------------------------
-
- parameters nBear1, nBear2, nRun
- if m->nBear2 > 180
- if m->nBear1 < m->nBear2 .or. m->nBear2 < 270
- RETURN -1
- else
- m->nBear1 = 360 - m->nBear1
- m->nBear2 = 360 - m->nBear2
- endif
- else
- if m->nBear2 < m->nBear1 .or. m->nBear2 > 90
- RETURN -1
- endif
- endif
-
- RETURN sin( dtor( m->nBear1 ) ) * m->nRun / sin( dtor( m->nBear2 - ;
- m->nBear1 ) )
- *-- EoF: BearsDist()
-
- FUNCTION BearsPass
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Distance at which the object will be passed abeam:
- *-- * <-- Object
- *-- . /|
- *-- . / |
- *-- 1-->-->-->--2 > 3 >
- *-- Where 1 = Position at time first bearing to object is
- *-- taken,
- *-- 2 = position at second bearing,
- *-- 3 = position at which the object will be abeam.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: BearsPass(<nBear1>,<nBear2>,<nRun>)
- *-- Example.....: ?BearsPass(200,150,5)
- *-- Returns.....: Numeric (degrees)
- *-- Parameters..: nBear1 = Bearing of First object
- *-- nBear2 = Bearing of Second object
- *-- nRun = Distance (or time) run between bearings
- *-----------------------------------------------------------------------
-
- parameters nBear1, nBear2, nRun
- private nTemp
- if m->nBear2 > 180
- if m->nBear1 < m->nBear2 .or. m->nBear2 < 270
- RETURN -1
- else
- m->nBear1 = 360 - m->nBear1
- m->nBear2 = 360 - m->nBear2
- endif
- else
- if m->nBear2 < m->nBear1 .or. m->nBear2 > 90
- RETURN -1
- endif
- endif
- m->nTemp = sin( dtor( m->nBear1 ) ) * ;
- m->nRun / sin( dtor( m->nBear2 - m->nBear1 ) )
-
- RETURN m->nTemp * sin( dtor( m->nBear2 ) )
- *-- EoF: BearsPass()
-
- FUNCTION BearsRun
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Distance to run until object will be abeam given two
- *-- bearings. Same rules and restrictions as bearsdist().
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: BearsRun(<nBear1>,<nBear2>,<nRun>)
- *-- Example.....: ?BearsRun(200,150,5)
- *-- Returns.....: Numeric (degrees)
- *-- Parameters..: nBear1 = Bearing of First object
- *-- nBear2 = Bearing of Second object
- *-- nRun = Distance (or time) run between bearings
- *-----------------------------------------------------------------------
-
- parameters nBear1, nBear2, nRun
- private nTemp
- if m->nBear2 > 180
- if m->nBear1 < m->nBear2 .or. m->nBear2 < 270
- RETURN -1
- else
- m->nBear1 = 360 - m->nBear1
- m->nBear2 = 360 - m->nBear2
- endif
- else
- if m->nBear2 < m->nBear1 .or. m->nBear2 > 90
- RETURN -1
- endif
- endif
- m->nTemp = sin( dtor( m->nBear1 ) ) * ;
- m->nRun / sin( dtor( m->nBear2 - m->nBear1 ) )
-
- RETURN m->nTemp * cos( dtor( m->nBear2 ) )
- *-- EoF: BearsRun()
-
- FUNCTION GcDist
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Great circle distance between two points given
- *-- latitude and longitude of each. This function obtains
- *-- the degrees of arc along the great circle and simply
- *-- multiplies by 60 to convert the degrees to nautical
- *-- miles. As this ignores the eccentricity of the earth,
- *-- the answer may be in error by approximately half of
- *-- one percent. In general, if the route lies close to
- *-- the equator the result of this function will be
- *-- smaller than the actual number of nautical miles, but
- *-- if the route passes close to the poles the function
- *-- result will be larger than the correct number.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: DEG2NUM() Function in NAVIGATE.PRG
- *-- HAV() Function in TRIG.PRG
- *-- AHAV() Function in TRIG.PRG
- *-- Called by...: Any
- *-- Usage.......: GCDist(<cLat1>,<cLon1>,<cLat2>,<cLon2>)
- *-- Example.....: ?GCDist(200,150,105,200)
- *-- Returns.....: Numeric (nautical miles)
- *-- Parameters..: cLat1 = Latitude 1
- *-- cLon1 = Longitude 1
- *-- cLat2 = Latitude 2
- *-- cLon2 = Longitude 2
- *-----------------------------------------------------------------------
-
- parameters cLat1, cLon1, cLat2, cLon2
- private nLa1, nLo1, nLa2, nLo2, nDla, nDlo, nTemp
- m->nLa1 = dtor( deg2num( m->cLat1 ) )
- m->nLo1 = dtor( deg2num( m->cLon1 ) )
- m->nLa2 = dtor( deg2num( m->cLat2 ) )
- m->nLo2 = dtor( deg2num( m->cLon2 ) )
- m->nDla = abs( m->nLa1 - m->nLa2 )
- m->nDlo = abs( m->nLo2 - m->nLo1 )
- do case
- case m->nDlo = 0 .or. m->nDla = pi()
- RETURN 60 * rtod( m->nDla )
- case m->nDlo = pi()
- RETURN 60 * rtod( ( pi() - m->nDla ) )
- case m->nDlo > pi()
- m->nDlo = 2 * pi() - m->nDlo
- endcase
- m->nTemp = hav( m->nDla ) + hav( m->nDlo ) * cos( m->nLa1 ) *;
- cos( m->nLa2 )
-
- RETURN 60 * rtod( ahav( m->nTemp ) )
- *-- EoF: GcDist()
-
- FUNCTION GcCourse
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Initial great circle course between two points given
- *-- latitude and longitude of each. Returns -1 if the
- *-- points are antipodes.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: DEG2NUM() Function in NAVIGATE.PRG
- *-- HAV() Function in TRIG.PRG
- *-- AHAV() Function in TRIG.PRG
- *-- CSCH() Function in TRIG.PRG
- *-- Called by...: Any
- *-- Usage.......: GCCourse(<cLat1>,<cLon1>,<cLat2>,<cLon2>)
- *-- Example.....: ?GCCourse(200,150,105,200)
- *-- Returns.....: Numeric (degrees)
- *-- Parameters..: cLat1 = Latitude 1
- *-- cLon1 = Longitude 1
- *-- cLat2 = Latitude 2
- *-- cLon2 = Longitude 2
- *-----------------------------------------------------------------------
-
- parameters nLat1, nLon1, nLat2, nLon2
- private nLa1, nLo1, nLa2, nLo2, nDla, nDlo, nTemp, lRev
- m->nLa1 = dtor( deg2num( m->nLat1 ) )
- m->nLo1 = dtor( deg2num( m->nLon1 ) )
- m->nLa2 = dtor( deg2num( m->nLat2 ) )
- m->nLo2 = dtor( deg2num( m->nLon2 ) )
- m->nDla = abs( m->nLa1 - m->nLa2 )
- m->nDlo = abs( m->nLo2 - m->nLo1 )
- m->lRev = .F.
- do case
- case m->nDla =pi() .or. m->nDlo = pi () .and. m->nLa1 + m->nLa2 =0
- RETURN -1
- case m->nDlo =0 .or. m->nDlo = pi() .or. abs( m->nLa1) =pi() .or.;
- abs( m->nLa2 ) = pi()
- RETURN iif( La1 > La2 , 180, 0 )
- case m->nDlo > pi()
- m->nDlo = 2 * pi() - m->nDlo
- m->lRev = .T.
- endcase
- m->nTemp = hav( m->nDla ) + hav( m->nDlo ) * cos( m->nLa1 ) *;
- cos( m->nLa2 )
- m->nTemp = rtod( asin( sin( m->nDlo ) * cos( m->nLa2 ) *;
- csch( ahav( m->nTemp ) ) ) )
- m->nTemp = iif( m->nLa1 > m->nLa2, 180 - m->nTemp, m->nTemp )
-
- RETURN iif( ( m->nLo2 > m->nLo1 ) = m->lRev, m->nTemp, 360 - m->nTemp )
- *-- EoF: GCCourse()
-
- *-----------------------------------------------------------------------
- *-- For convenience the following routines were brought in from other
- *-- library files.
- *-----------------------------------------------------------------------
-
- FUNCTION Strip2Val
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Strip characters from the left of a string until
- *-- reaching one that might start a number.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Strip2Val("<cStr>")
- *-- Example.....: ? Strip2Val("Test345")
- *-- Returns.....: character string
- *-- Parameters..: cStr = string to search
- *-----------------------------------------------------------------------
-
- parameters cStr
- private cNew
- m->cNew = m->cStr
- do while "" # m->cNew
- if left( m->cNew, 1 ) $ "-.0123456789"
- exit
- endif
- m->cNew = substr( m->cNew, 2 )
- enddo
-
- RETURN m->cNew
- *-- EoF: Strip2Val()
-
- FUNCTION StripVal
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Strip characters from the left of the string until
- *-- reaching one that is not part of a number. A hyphen
- *-- following numerics, or a second period,
- *-- is treated as not part of a number.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StripVal("<cStr>")
- *-- Example.....: ? StripVal("123.2Test")
- *-- Returns.....: Character
- *-- Parameters..: cStr = string to test
- *-----------------------------------------------------------------------
-
- parameters cStr
- private cNew, cChar, lGotminus, lGotdot
- m->cNew = m->cStr
- store .f. to m->lGotMinus, m->lGotDot
- do while "" # m->cNew
- m->cChar = left( m->cNew, 1 )
- do case
- case .not. m->cChar $ "-.0123456789"
- exit
- case m->cChar = "-"
- if m->lGotMinus
- exit
- endif
- case m->cChar = "."
- if m->lGotDot
- exit
- else
- m->lGotDot = .T.
- endif
- endcase
- m->cNew = substr( m->cNew, 2 )
- m->lGotMinus = .T.
- enddo
-
- RETURN m->cNew
- *-- EoF: StripVal()
-
- FUNCTION StrPBrk
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Search string for first occurrence of any of the
- *-- characters in charset. Returns its position as
- *-- with at(). Contrary to ANSI.C definition, returns
- *-- 0 if none of characters is found.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StrPBrk("<cCharSet>","<cBigStr>")
- *-- Example.....: ? StrPBrk("Tt",;
- *-- "This is a Test string, with Test data")
- *-- Returns.....: Numeric value
- *-- Parameters..: cCharSet = characters to look for in cBigStr
- *-- cBigStr = string to look in
- *-----------------------------------------------------------------------
-
- parameters cCharset, cBigstring
- private nPos, nLooklen
- m->nPos = 0
- m->nLooklen = len( m->cBigString )
- do while m->nPos < m->nLooklen
- m->nPos = m->nPos + 1
- if at( substr( m->cBigString, m->nPos, 1 ), m->cCharset ) > 0
- exit
- endif
- enddo
-
- RETURN iif(m->nPos=m->nLooklen,0,m->nPos)
- *-- EoF: StrPBrk()
-
- FUNCTION Hav
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Haversine of an angle in radians
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Hav(<nX>)
- *-- Example.....: ?Hav(48)
- *-- Returns.....: Numeric
- *-- Parameters..: nX = Return Hav of X
- *-----------------------------------------------------------------------
-
- parameters nX
-
- RETURN ( 1 - cos( m->nX ) ) / 2
- *-- EoF: Hav()
-
- FUNCTION AHav
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Inverse haversine - angle size in radians for given
- *-- haversine
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: AHav(<nX>)
- *-- Example.....: ?AHav(48)
- *-- Returns.....: Numeric
- *-- Parameters..: nX = Return AHav of X
- *-----------------------------------------------------------------------
-
- parameters nX
-
- RETURN acos( 1 - 2 * m->nX )
- *-- EoF: AHav()
-
- FUNCTION SinH
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Hyperbolic sine of an angle X in radians
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: SinH(<nX>)
- *-- Example.....: ?SinH(48)
- *-- Returns.....: Numeric
- *-- Parameters..: nX = Return SinH of X
- *-----------------------------------------------------------------------
-
- parameters m->nX
-
- RETURN ( exp( m->nX ) - exp( -m->nX ) ) / 2
- *-- EoF: SinH()
-
- FUNCTION CScH
- *-----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Hyperbolic cosecant of an angle X in radians
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 03/01/1993 -- Original Release
- *-- Calls.......: SINH() Function in TRIG.PRG
- *-- Called by...: Any
- *-- Usage.......: CScH(<nX>)
- *-- Example.....: ?CScH(48)
- *-- Returns.....: Numeric
- *-- Parameters..: nX = Return CScH of X
- *-----------------------------------------------------------------------
-
- parameters nX
-
- RETURN 1 / sinh( m->nX )
- *-- EoF: CScH()
-
- *-----------------------------------------------------------------------
- *-- EoP: NAVIGATE.PRG
- *-----------------------------------------------------------------------